#include <surftrack.h>
#include <subdivisionscheme.h>
#include <vector>
#include "mex.h"

#pragma comment(lib, "eltopo")
#pragma comment(lib, "imager")
#pragma comment(lib, "cblas")
#pragma comment(lib, "gsl")

using namespace std;

SurfTrack* surf = NULL; 

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
    SurfTrackInitializationParameters params;

	params.m_min_edge_length = 0.01;
	params.m_max_edge_length = 0.1;
	params.m_max_volume_change = 0.025;
	params.m_min_triangle_angle = 15;
	params.m_max_triangle_angle = 165;
	params.m_min_triangle_area = 0.00001;
	params.m_merge_proximity_epsilon = 0.00001;
	params.m_proximity_epsilon = 0.00001;
	params.m_friction_coefficient = 1;

	params.m_use_curvature_when_splitting = false;
	params.m_use_curvature_when_collapsing = false;
	params.m_perform_improvement = true;
	params.m_allow_topology_changes = true;
	params.m_collision_safety = false;
	params.m_allow_non_manifold = false;
	params.m_allow_vertex_movement = false;

	params.m_subdivision_scheme = new MidpointScheme();

	params.m_min_curvature_multiplier;
	params.m_max_curvature_multiplier;

	vector<Vec3ui> tris;
	vector<Vec3d> verts;
	vector<Vec3d> vels;
	vector<double> masses;

	verts.push_back(Vec3d(0,0,0));
	verts.push_back(Vec3d(1,0,0));
	verts.push_back(Vec3d(0,1,0));
	verts.push_back(Vec3d(0,0,1));

	tris.push_back(Vec3ui(0,1,3));
	tris.push_back(Vec3ui(0,2,1));
	tris.push_back(Vec3ui(0,3,2));
	tris.push_back(Vec3ui(1,2,3));

	vels.push_back(Vec3d(0,0,0));
	vels.push_back(Vec3d(0,0,0));
	vels.push_back(Vec3d(0,0,0));
	vels.push_back(Vec3d(0,0,0));

	masses.push_back(1);
	masses.push_back(1);
	masses.push_back(1);
	masses.push_back(1);

	surf = new SurfTrack(verts, tris, masses, params);

	surf->defrag_mesh();
	surf->m_collision_pipeline.assert_mesh_is_intersection_free(false);
    
    surf->improve_mesh();
	surf->topology_changes();
	surf->defrag_mesh();
    
    mexPrintf("hello world");
    
	return;
}